package  src;
/**
 * The Constant class, in which implement the Expression Interface, represents
 * a constant number expression.
 * A Constant can be evaluated, derived and return its last operation symbol.
 *
 * @author Intro111 Staff
 */
//this is the first change//

public class Constant implements Expression {

    private double value;

    /**
     * Constructor in which creates a constant expression with a given value
     *
     * @param num the value of the constant expression
     */
    public Constant(double num) {
        value = num;
    }

    /**
     * Constructor in which creates a constant expression with value 0
     */
    public Constant() {
        this(0);
    }

    /**
     * Derives the Constant expression by a variable, which is simply
     * a constant expression with value 0.
     *
     * @param var the variable to derive by
     * @return Constant Expression with value 0
     * @throws RuntimeException for a null var
     */
    public Expression derivative(Variable var) {
        if (var == null) {
            throw new RuntimeException("Constant derivative(Variable var) got a null argument.");
        }
        return new Constant();
    }

    /**
     * Get the constant expression value.
     *
     * @return the Constant Expression value.
     */
    public double evaluate() {
        return value;
    }

    /**
     * Get the last operation symbol of the constant expression, which is simply the empty String "".
     *
     * @return String empty String ""
     */

    public String getLastOperationSymbol() {
        return "";
    }

    /**
     * Compares this expression to the specified object.
     * The result is true if and only if the argument is not null, the argument is instance of Constant and has ths same value as the current constant expression.
     *
     * @param other The object to compare this expression against
     * @return true if the given object represents an expression equivalent to this expression, false otherwise
     */
    public boolean equals(Object other) {
        return ((other instanceof Constant) &&
                (value == ((Constant) other).value));
    }

    /**
     * Returns a string representing the Constant Expression.
     *
     * @return String that represents the Constant Expression
     */
    public String toString() {
        return "" + value;
    }

}
